<?php

use yii\helpers\Html;
use yii\bootstrap\Modal;
use yii\helpers\Url;
use common\libs\Constants;
use mdm\admin\components\Helper;
use kartik\grid\GridView;
use backend\modules\spread\models\SpreadInfoSearch;

/* @var $this View */
/* @var $searchModel SpreadInfoSearch */
/* @var $dataProvider ActiveDataProvider */

$this->title = Yii::t('modules/spread/default', 'Spread Infos');
$this->params['breadcrumbs'][] = $this->title;

Modal::begin([
    'id'=>'operate-modal',
    'header'=>'<h4 class="modal-title"></h4>'
]);
Modal::end();
$createUrl = Url::toRoute('create');
$viewUrl = Url::toRoute('view');
$updateUrl = Url::toRoute('update');
$uploadUrl = Url::toRoute('upload');
$createTitle = Yii::t('modules/spread/default','Create Spread Info');
$updateTitle = Yii::t('modules/spread/default','Update Spread Info');
$viewTitle = Yii::t('modules/spread/default','View Spread Info');
$uploadTitle = Yii::t('modules/spread/default','Upload Spread Info');

$js = <<<JS
// 创建操作
$('#create').on('click', function () {
    $('.modal-dialog').removeClass('modal-lg');
    $('.modal-title').html('{$createTitle}');
    $.get('{$createUrl}',
        function (data) {
            $('.modal-body').html(data);
        }
    );
});
// 详情信息
$('.btn-view').on('click', function () {
    $('.modal-dialog').addClass('modal-lg');
    $('.modal-title').html('{$viewTitle}');
    $.get('{$viewUrl}', { id: $(this).closest('tr').data('key') },
        function (data) {
            $('.modal-body').html(data);
        }
    );
});
// 详情信息
$('.btn-upload').on('click', function () {
    $('.modal-dialog').addClass('modal-lg');
    $('.modal-title').html('{$uploadTitle}');
    $.get('{$uploadUrl}', { id: $(this).closest('tr').data('key') },
        function (data) {
            $('.modal-body').html(data);
        }
    );
});
// 更新操作
$('.btn-update').on('click', function () {
    $('.modal-dialog').removeClass('modal-lg');
    $('.modal-title').html('{$updateTitle}');
    $.get('{$updateUrl}', { id: $(this).closest('tr').data('key') },
        function (data) {
            $('.modal-body').html(data);
        }
    );
});
JS;
$this->registerJs($js);

?>
<div class="spread-info-index">
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
    <?php if(Helper::checkRoute('create')) { ?>
    <p>
        <?= Html::a(Yii::t('modules/spread/default', 'Create Spread Info'), ['create'],
        [
            'class' => 'btn btn-success',
            'id' => 'create',
            'data-toggle' => 'modal',
            'data-target' => '#operate-modal'
        ]) ?>
    </p>
    <?php }?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
//            'guild_sign',
//            'spread_key_1',
//            'spread_key_2',
            'spread_url:url',
             'spread_surl:url',
            [
                'attribute'=>'game_name',
                'value'=>'game.game_name',
                'label'=>'游戏'
            ],
            [
                'attribute'=>'server_name',
                'value'=>'server.server_name',
                'label'=>'区服'
            ],
//    [
//        'class' => 'yii\grid\ActionColumn',
//        'template' => Helper::filterActionColumn('{view}{upload}{update}{delete}'),
//        //                'header' => '操作',
//        'headerOptions' => [
//            'width' => '100px',
//        ],
//        'buttons' => [
//            'view' => function($url, $model, $key){
//                return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [
//                      'title' => '详情',
//                      'class' => 'btn btn-default btn-view',
//                      'data-toggle' => 'modal',
//                      'data-target' => '#operate-modal',
//                      ]);
//              },
//
//            'update' => function($url, $model, $key) {
//                return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
//                           'title' => '编辑',
//                           'class' => 'btn btn-default btn-update',
//                           'data-toggle' => 'modal',
//                           'data-target' => '#operate-modal',
//                        ]);
//            },
//            'delete' => function($url, $model, $key) {
//                return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
//                    'title' => '删除',
//                    'class' => 'btn btn-default',
//                    'data' => [
//                        'confirm' => '确定要删除么?',
//                        'method' => 'post',
//                    ],
//                ]);
//            },
//        ],
//    ],
],
    ]); ?>
</div>